USE [CASASHOW]
GO
/****** Object:  StoredProcedure [dbo].[SP08_CONSULTA_INGRESSO]    Script Date: 11/19/2013 12:02:39 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP08_CONSULTA_INGRESSO]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SP08_CONSULTA_INGRESSO]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[SP08_CONSULTA_INGRESSO]
       @ID_INGRESSO INT
AS
/******      Declaracao das variaveis locais - NUNCA utilize os parametros de entrada nos comandos SQL 
*/

DECLARE @V_ID_INGRESSO INT
SET @V_ID_INGRESSO = @ID_INGRESSO

/******      Crie a logica da procedure abaixo
*/

IF @V_ID_INGRESSO IS NULL  
BEGIN
	SELECT ID_INGRESSO, ID_SHOW, IC_INGRESSO_DISPONIVEL
	FROM TB05_INGRESSO
	WHERE IC_INGRESSO_DISPONIVEL = 1
END
ELSE
BEGIN
	SELECT ID_INGRESSO, ID_SHOW, IC_INGRESSO_DISPONIVEL
	FROM TB05_INGRESSO TB05
	WHERE TB05.ID_INGRESSO = @V_ID_INGRESSO
	  AND IC_INGRESSO_DISPONIVEL = 1
END

